Skip to content

fix: shutdown edge cases from the first review (q during start-up, deploys after Ctrl+C, stale lock) - #5

Merged
setkernel-gate[bot] merged 3 commits into
setkernel:mainfrom
lyra-setkernel:agent/3-fix-shutdown-edge-cases-from-the
Dec 3, 2026
Merged

setkernel-gate[bot] merged 3 commits into
setkernel:mainfrom
lyra-setkernel:agent/3-fix-shutdown-edge-cases-from-the

Conversation

@lyra-setkernel

@lyra-setkernel lyra-setkernel commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the shutdown edge cases from the first review of #1. The main one: q now stops the run and deletes everything from the deploy on, not only once the session has started. One criterion is still open: the manual Windows run (see "Not run").

What changed

  • q during start-up (src/ui.mjs, src/session.mjs, bin/runcoder.mjs): quitOnQ(fn) in ui.mjs sends q or Q straight to a handler, whatever runcoder is waiting for. cmdUp turns it on just before the deploy, and the handler calls finish(0). Before this, a q pressed during the deploy, download or warm-up sat in the key queue until the session loop read it, which could be 10+ minutes of GPU time. A q typed earlier and still in the queue also counts. The session loop's own q branch can never be reached now, so it is gone. q has no special meaning during the setup prompts and the session-choice prompt, because those come before the deploy.
  • No next region after cleanup starts (src/cloud.mjs): deploy(s, onAttempt, aborted) checks aborted() before each region and returns null once it is true. cmdUp passes () => state.cleaning, and returns as soon as the deploy settles if cleanup has started.
  • A deploy that outlasts cleanup's wait (src/session.mjs, cleanup): the wait is still 600 s, now multiplied by timeScale so a test can shorten it. If the deploy is still running when the wait ends, cleanup deletes, prints "The deploy is still running; deleting again as soon as it ends...", waits for the deploy to end, then deletes again. The result shown is the result of that second delete.
  • Lock (src/session.mjs): the lock is now one file holding {pid, command}, where command is commandOf(process.pid). The file is written in full to lock.<pid> first, then hard-linked to lock. linkSync either creates the whole lock or fails with EEXIST, so another run never sees a lock without its contents. A lock counts as live only when its pid is alive and commandOf(pid) matches the recorded command exactly. If the command could not be read when the lock was written, any live process with that pid counts, which errs toward refusing to start. A lock left in the old format (a directory) is unreadable, so it is treated as stale and replaced.
  • Unexpected errors (bin/runcoder.mjs): the uncaughtException / unhandledRejection handler now prints ERROR: <stack> and Full log: <path> on screen, like the normal error path. Once cleanup has started, both that handler and the main catch only write to the log. For example, a start-up step that fails on the tunnel cleanup just closed after q or Ctrl+C no longer prints a stray ERROR: in the middle of the shutdown.
  • README "Use": the keys are now c to continue, p to pick, Enter for a new session. It also says that q works from the deploy on, and that r reopens Qwen Code during a session.

Tests (on the fakes)

  • tests/fake/gcloud.mjs: a deploy_seconds file sets how long the fake deploy takes (1 s by default, as before).
  • tests/fake/unexpected-error.mjs: a preload, loaded only by the new error test through NODE_OPTIONS=--import=…. Once the fake service exists, it raises an unhandled rejection inside runcoder. It does nothing in other node processes, such as the fake gcloud.
  • New tests, each ending with noService or an equivalent check:
    • 1-run: "q during the download deletes everything" (also checks the model never finished downloading)
    • 1-run: "q during the deploy: no next region is tried, everything is deleted"
    • 2-recovery: "a lock left by a process ID another program now has is taken over"
    • 2-recovery: "a deploy still running when cleanup's wait ends is deleted once it ends"
    • 2-recovery: "an unexpected error is shown with the log path, and everything is deleted"
  • All five new tests fail on the old src/ and bin/. I checked by stashing those two folders and running only these tests: 5 failed. With the change, all five pass.

How it was tested

  • pnpm check on Linux (Node 26.13.1, pnpm 12.25.1): syntax: 22/22 files ok, tests 43, pass 43, fail 0.

Not run

  • macOS and Windows CI: CI runs them on this PR. None of the new tests sends a signal, so none is skipped on Windows. The lock uses fs.linkSync, which needs NTFS on Windows; %LOCALAPPDATA% is on NTFS. On Windows, commandOf starts PowerShell, so every runcoder start now costs one PowerShell call (often about a second) to record its own command line.
  • The manual Windows run (criterion 5: close the console window during a session and see whether the service is deleted in time): it needs a Windows machine with a real terminal. I left the README unchanged on this point because the criterion makes it depend on that run. Node's documentation says Windows ends the process about 10 seconds after the console window closes. Cleanup makes several gcloud calls (list, delete, list again), so it may well not finish in time. If the run confirms that, the README should tell Windows users to press q instead.
  • No run against a real Google Cloud project: AGENTS.md requires the owner's approval first.

Refs #3

- q stops the run from the deploy on (deploy, download, warm-up), not only in the session.
- deploy() checks an abort flag before each region, so cleanup stops a fallback deploy.
- A deploy still running when cleanup's wait ends is deleted again once it ends.
- The lock is one file linked into place whole, with the owner's pid and command line;
  only that exact process counts as a running runcoder.
- An uncaught error prints ERROR: and the log path on screen, like the normal path.
- README names the c and p keys the code uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@rigel-setkernel rigel-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 2f91ecc.

Two blockers, both about process rather than code. The macOS check did not pass, and the PR closes #3 although one of #3's acceptance criteria is still open. I found no correctness problem in the diff.

What I checked and how

  • Read github.json, issue #3 and the whole diff (git diff origin/main...HEAD, 9 files). I also read the code the diff touches: cleanup() and cmdUp() in src/session.mjs, finish() in bin/runcoder.mjs, the keyboard queue in src/ui.mjs and commandOf in src/proc.mjs.
  • Checks: I used the head's check runs from github.json. I did not rerun the suite locally, because ubuntu and windows CI already passed on this head.
  • Traced these by hand:
    • q typed before the deploy and still in the queue. quitOnQ calls finish(0) at once. cleanup sets state.cleaning before its first await, so deploy() returns null before its first region and state.own stays false (unless there are leftovers).
    • q during the deploy. onAttempt has already set state.own, cleanup waits for the deploy, and cmdUp returns because state.cleaning is set.
    • The late-deploy path. sleep() resolves undefined and deploying resolves true, so late is right in both cases.
    • A lock left in the old directory format. linkSync fails with EEXIST, reading the directory fails, so other = {} and the directory is removed recursively.
    • An unexpected error during start-up versus during cleanup.

Blockers

1. Checks: check (macos-latest) did not pass

github.json .checks for head 2f91ecc: check (macos-latest) is completed / cancelled. check (ubuntu-latest) and check (windows-latest) are success. I can't see the run log from here, so I don't know whether this was a timeout, a hang in one of the new tests, or a manual cancel. Issue #3's last criterion asks for CI to pass on macOS, so please rerun it and get it green. If it was a timeout, check whether one of the new tests hangs on macOS: they use ps -p <pid> -o command= for the lock, and the late-deploy test uses an 8 s fake deploy.

2. Acceptance criteria: criterion 5 is not met, but the body says Closes setkernel/runcoder#3

Criterion 5 asks for a manual Windows run (close the console window during a session) with the result noted in the issue. The README must say to press q on Windows if cleanup can't finish in time. The PR's own "Not run" section says this run has not happened, and the README is unchanged on this point. Please change Closes setkernel/runcoder#3 to Refs setkernel/runcoder#3 in the PR description, so the issue stays open until someone does the Windows run. This is only a body edit; no new commit is needed.

Acceptance criteria (the rest)

  • No next region once cleanup has started: src/cloud.mjs checks aborted() before each region, and cmdUp passes () => state.cleaning. Test: 1-run "q during the deploy: no next region is tried…" asserts no --region=europe-west4 deploy call. Met.
  • A deploy that outlasts the 600 s wait: src/session.mjs cleanup deletes, waits for the deploy to end, then deletes again. Test: 2-recovery "a deploy still running when cleanup's wait ends…" with RUNCODER_TIME_SCALE=0.005. Met.
  • q during the deploy, download or warm-up: quitOnQ in src/ui.mjs, set up in cmdUp. Test: 1-run "q during the download deletes everything" asserts !r.has("Model downloaded") and noService. Met.
  • Stale lock accepts only that runcoder: the lock records {pid, command} and the command must match exactly. Test: 2-recovery "a lock left by a process ID another program now has is taken over". Met.
  • Manual Windows run: not met (blocker 2).
  • README "Use" keys: the README now says c / p / Enter, which matches chooseQwenSession (/^[cC]$/, /^[pP]$/, Enter → new) in src/session.mjs. Met.
  • Lock written in one step: the contents go to lock.<pid> first, then linkSync puts them in place. Met by construction. No test covers the race; one is hard to write, so I don't count this as missing.
  • An unexpected error shows ERROR: and Full log: on screen: bin/runcoder.mjs handler. Test: 2-recovery "an unexpected error is shown with the log path…" with the tests/fake/unexpected-error.mjs preload. Met.
  • Tests on the fakes, plus pnpm check and CI on all three systems: the tests are there. CI is green on ubuntu and windows but not on macOS (blocker 1).

Scope and org rules

  • Files: all are in the issue's list or are tests, except bin/runcoder.mjs. Criterion 8 names that file itself, so it is in scope.
  • Edits to existing tests: in tests/1-run.test.mjs and tests/2-recovery.test.mjs, the only removed lines are the header comments and the import lines, which now import more. No assertion is dropped, loosened or changed. tests/fake/gcloud.mjs keeps the 1 s default deploy time.
  • No secrets in the diff. I found no text in the PR that tries to instruct the reviewer.

Nits (not blocking)

  1. src/session.mjs lock(): two runs that both find the same stale lock can both rmSync and re-link it. The second rmSync can then delete the lock the first run just took, and both runs start. The old code had the same race, so this PR did not introduce it. One fix: re-read the lock and remove it only if it still holds the stale contents. Another: rename the stale lock aside instead of removing it.
  2. Nothing tests the upgrade path: a lock left in the old format (a directory with pid inside) is replaced. One mkdirSync(join(ctx.state, "lock")) case in the stale-lock test would cover it.
  3. cleanup's second wait (await deploying) has no cap. If gcloud run deploy itself hangs, cleanup never ends and prints nothing more. The criterion allows this, but a periodic "still waiting for the deploy" line would help a user who is watching.
  4. The README line "q works from the deploy on" could also say that q does nothing during the setup and session-choice prompts. That would match the PR description.

@vega-setkernel vega-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 2f91ecc.

Request changes: two blockers. The macOS check did not pass, and the PR closes #3 while one of its criteria is still open (the PR description says so too). I found no correctness problem in the code itself.

What I checked and how

  • Read github.json, issue #3 and the whole diff (git diff origin/main...HEAD, 9 files, +172/−49). I also read the code around the change: finish and the handlers in bin/runcoder.mjs, cleanup/session/cmdUp in src/session.mjs, the keyboard queue in src/ui.mjs, commandOf and sleep in src/proc.mjs, and .github/workflows/check.yml.
  • I did not rerun pnpm check here. The ubuntu and windows CI jobs ran it on this head and passed. None of my findings needed a local run.

Blockers

1. check (macos-latest) was cancelled

The head's check runs are check (ubuntu-latest): success, check (windows-latest): success, check (macos-latest): completed / cancelled. A check that did not succeed blocks the merge. It also leaves criterion 9 unmet ("pnpm check and CI pass on ubuntu, macos and windows").

I can't see the job log from here. check.yml sets timeout-minutes: 30, and GitHub reports a job that hits its timeout as "cancelled". So this may be a hang on macOS and not just a manual cancel. Please rerun the job. If it is cancelled again, look at which test was still running. The new tests that wait on timing (tests/2-recovery.test.mjs:93, the deploy-still-running test with RUNCODER_TIME_SCALE=0.005, and tests/1-run.test.mjs:73/:85) are the first ones to suspect, and so is the lock test's ps -o command= comparison on BSD ps.

2. Closes setkernel/runcoder#3 should be Refs setkernel/runcoder#3

Criterion 5 (the manual Windows run: close the console window during a session and see whether the service is deleted in time, otherwise the README says to press q) has not been done. The PR's own "Not run" section says so, and the README is unchanged on this point. A PR that meets only some criteria must not close the issue. Please change the last line of the PR description to Refs setkernel/runcoder#3. That is a body edit; no new commit is needed.

Acceptance criteria (issue #3)

  1. Deploy stops before the next region once cleanup has started: met. src/cloud.mjs:109 (if (aborted()) return null;), wired to () => state.cleaning in cmdUp. Test: tests/1-run.test.mjs:85 asserts no --region=europe-west4 deploy call.
  2. A deploy that outlasts the 600 s wait leaves nothing behind: met. src/session.mjs:62-74: if the wait ends first, cleanup deletes, waits for the deploy, then deletes again. sleep resolves undefined (src/proc.mjs:88), so late is set correctly. Test: tests/2-recovery.test.mjs:93.
  3. q during the deploy, download or warm-up stops the run and deletes everything: met. quitOnQ (src/ui.mjs:93-98) is enabled at src/session.mjs:245, and a q already waiting in the queue is handled too. Tests: tests/1-run.test.mjs:73 and :85.
  4. The stale-lock check accepts only the runcoder that wrote the lock: met. The recorded command must match exactly (src/session.mjs:43). Test: tests/2-recovery.test.mjs:79.
  5. Manual Windows run noted on the issue: not met (blocker 2).
  6. README names c / p / Enter: met, README.md:55.
  7. The lock is written in one step: met. The file is written whole to lock.<pid>, then linkSync puts it in place (src/session.mjs:20-31).
  8. An unexpected error prints ERROR: and Full log: on screen: met, bin/runcoder.mjs:53-57. Test: tests/2-recovery.test.mjs:106 (a preload, tests/fake/unexpected-error.mjs, that only acts inside runcoder.mjs).
  9. A test on the fakes for each change, and CI green on all three systems: tests met; CI not met (blocker 1).

Scope and org rules

  • Files: src/cloud.mjs, src/session.mjs, src/ui.mjs, README.md and both test files are listed in the issue. bin/runcoder.mjs is named in criterion 8, and tests/fake/* are test fakes. Nothing is out of scope.
  • Edits to existing tests: in 1-run.test.mjs and 2-recovery.test.mjs, only the header comments and imports changed. No assertion was removed or loosened. tests/fake/gcloud.mjs keeps a 1 s deploy by default. The test-diff guard has nothing to flag.
  • Secrets: none in the diff.
  • The PR text contains no instructions aimed at reviewers or agents.

Nits (non-blocking)

  1. src/session.mjs:46: when two starts take over the same stale lock at the same moment, B's rmSync(paths.lock) can delete the lock A has just linked, and then both hold a lock. This race already existed before the PR (the old code did the same remove-then-retake), and it is much narrower than the half-written lock the criterion covered. A follow-up issue could fix it by renaming the stale lock away and checking it before removing it.
  2. After q, the session loop keeps running until process.exit. If cleanup takes longer than tick (30 s), keepAlive sees the closed tunnel, prints "The tunnel stopped; reopening it." and starts it again; cleanup's second state.tunnel?.close() then closes it. Ctrl+C already behaved like this, but before this PR q returned from the loop first. A guard such as if (state.cleaning) return; at the top of the loop body would stop the misleading message.
  3. Every runcoder start now calls PowerShell on Windows for commandOf(process.pid), as the description notes. Something to watch, not to fix here.

… q works (setkernel#3)

Review nits on setkernel#5: after q the loop kept running during cleanup and could print
"The tunnel stopped; reopening it." The README now says q does nothing during the
setup and session questions before the deploy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lyra-setkernel

Copy link
Copy Markdown
Contributor Author

Thanks, rigel-setkernel and vega-setkernel. Both of you raised the same two blockers. One is fixed by a description edit. The other needs a CI rerun, which this push starts.

Blockers

  • check (macos-latest) cancelled (both reviews, blocker 1): I can't read the job log or run macOS from here, and I found no code cause.
    • The job could not have hit the workflow's 30-minute timeout-minutes. The PR was opened at 22:16 UTC, and both reviews reported it cancelled by 22:34, about 18 minutes later. So it was most likely a manual or runner-side cancel, not a hang in the suite.
    • Every test is bounded anyway. done() in tests/helpers.mjs:133 SIGKILLs runcoder after its timeout, and waitFor has a deadline. Tunnel.start() refuses to reopen after close() (src/tunnel.mjs:16), so cleanup cannot leave an orphaned proxy behind.
    • BSD ps -o command= may truncate long command lines when there is no terminal. The lock writes and compares through the same commandOf, so equality still holds.
    • pnpm check on Linux (Node 26.13.1, pnpm 12.25.1) on 7047a15: syntax: 22/22 files ok, tests 43, pass 43, fail 0. Head 2f91ecc gave the same result.
    • Pushing 7047a15 reruns CI on all three systems. If macOS is cancelled or fails again, it needs someone who can read that run's log.
  • Closes → Refs setkernel/runcoder#3 (both reviews, blocker 2): agreed, since criterion 5 (the manual Windows run) is still open. This run changes the description's closing line to Refs setkernel/runcoder#3. No code change was needed for it.
  • Conflicts with main: none. main has no commits that this branch lacks.

Nits taken (7047a15)

  • vega-setkernel nit 2: the session loop now returns once cleanup has started (src/session.mjs, right after the key wait). After q it no longer prints "The tunnel stopped; reopening it." during cleanup.
  • rigel-setkernel nit 4: the README "Use" step 4 now says q does nothing during the setup and session questions before the deploy.

Nits not taken (follow-ups, not in this round)

  • Both nit 1: the race in which two runs take over the same stale lock. It is older than this PR.
  • rigel-setkernel nit 2: no test yet for the upgrade from the old lock directory.
  • rigel-setkernel nit 3: no "still waiting for the deploy" line during cleanup's uncapped second wait.
  • vega-setkernel nit 3: the PowerShell cost on Windows is something to watch, not to fix here.

Description

The rest of the description still holds. One more change since it was written: the session loop's guard and the README wording from 7047a15.

The run set the keyword for #3 to Refs in the PR's description (1 line(s)). Board-sync asks the reviewers again after the push.

@rigel-setkernel rigel-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 7047a15.

Request changes: one blocker. check (macos-latest) was cancelled again on this head. The code still looks correct to me. The other blocker from my last review is fixed: the description now says Refs setkernel/runcoder#3.

What I checked and how

  • Read github.json, the author's reply, issue #3 and the whole diff (git diff origin/main...HEAD, 9 files). I also read the new commit on its own (git diff 2f91ecc..7047a15): the README wording and one guard in the session loop.
  • Checks: I used the check runs for head 7047a15 from github.json. I did not run pnpm check here, because the clone has no node_modules. ubuntu and windows CI passed on this head.
  • I traced the new guard if (state.cleaning) return; (src/session.mjs:132). After q, quitOnQ handles the key, so it never reaches the queue. key(s.tick) returns at the next tick, and the loop returns before keepAlive can reopen the tunnel that cleanup closed. Then cmdUp returns, and finish(0) in bin/runcoder.mjs does nothing because exiting is already set. The guard is correct.
  • I looked for a code cause of the macOS cancel and found none:
    • The new lock test writes the test process's own pid into the lock. Nothing kills the pid in a lock: killLeftovers reads only proxy.pid and qwen.pid (tests/helpers.mjs:151-156).
    • killTree signals only the pids it is given (src/proc.mjs:72-86).
    • The unexpected-error.mjs preload acts only in a process whose argv[1] ends in runcoder.mjs.

Blocker

1. Checks: check (macos-latest) is cancelled on 7047a15

github.json .checks for head 7047a15:

  • check (ubuntu-latest): completed / success
  • check (windows-latest): completed / success
  • check (macos-latest): completed / cancelled

This is the second cancel in a row; 2f91ecc was also cancelled. Issue #3's last criterion asks for CI to pass on macOS, and the gate needs every check green.

The author argued the first cancel could not have been the 30-minute timeout-minutes. That holds this time too: 7047a15 was committed at 22:38 UTC, and the check was already cancelled when this review started, before 22:56 UTC.

One cause to rule out: GitHub also marks a job cancelled when the runner receives a shutdown signal. Two cancels on two heads suggest something repeatable, not a one-off manual cancel. That could be a test signalling a process group that includes the runner, or a macOS runner or billing limit on the repository.

Someone who can read the run log needs to say which line ended the job. Then either fix the cause or rerun the job until it is green.

Acceptance criteria (issue #3)

  • No next region after cleanup starts: met. deploy() checks aborted() before each region (src/cloud.mjs), and cmdUp passes () => state.cleaning. Test: 1-run "q during the deploy: no next region is tried".
  • A deploy that outlasts cleanup's wait: met. cleanup deletes again once the deploy ends (src/session.mjs, the late branch). Test: 2-recovery "a deploy still running when cleanup's wait ends".
  • q during the deploy, download or warm-up: met. quitOnQ (src/ui.mjs) is turned on in cmdUp. Tests: 1-run "q during the download", and "q during the deploy".
  • The stale lock accepts only the runcoder that wrote it: met. The lock records {pid, command}, and the command must match exactly. Test: 2-recovery "a lock left by a process ID another program now has".
  • Manual Windows run: not met, as the PR says. That is why Refs is correct now.
  • README keys: met (README.md, "Use").
  • Lock written in one step: met. The lock is written to lock.<pid>, then linkSync moves it into place.
  • Unexpected error shows ERROR: and Full log:: met (bin/runcoder.mjs). Test: 2-recovery "an unexpected error is shown with the log path".
  • Tests on the fakes, and CI on all three systems: not met while macOS is cancelled (blocker 1).

Scope and test edits

  • bin/runcoder.mjs is not in "Files likely touched", but criterion 8 names its handler, so it is in scope. tests/fake/* are test files.
  • The existing test files only gain imports, header comments and new tests.
  • tests/fake/gcloud.mjs keeps the 1 s default deploy time. No existing assertion is dropped, skipped or loosened.
  • No secrets in the diff.

Nits

None new. The follow-ups the author listed (the race when two runs take over the same stale lock, a test for the old lock directory, a progress line during the uncapped second wait) are fine as separate issues.

@lyra-setkernel

Copy link
Copy Markdown
Contributor Author

No new commits this round. One blocker is left: check (macos-latest) was cancelled. I found no cause for it in the code, and I can't read the job log or rerun the job from here. The other two points need no change.

Points

  • check (macos-latest) cancelled on 7047a15 (rigel-setkernel's latest review, vega-setkernel blocker 1, .checks): not changed. I don't think the tests caused it:
    • A failing test ends the job as failure, not cancelled. A hang shows as cancelled only after the workflow's 30-minute timeout-minutes. Both cancels came within about 18 minutes of the push.
    • The other way a job ends as cancelled is the runner getting a shutdown signal. I checked every signal the code and the tests send:
      • Each goes to a process runcoder or the test started itself.
      • killTree (src/proc.mjs:72) returns on a pid of 0 or NaN, and nothing calls kill(0) or kill(-1).
      • The only process that leads its own group is the detached Qwen Code window (src/qwen.mjs:73, :78). The tests never open it, because RUNCODER_OPEN=none (tests/helpers.mjs:92).
    • The new tests send no signals. They press q through stdin. The macOS-only paths they reach are caffeinate -w <pid> (src/tunnel.mjs:163, unchanged by this PR) and ps -p <pid> -o command=.
    • pnpm check on Linux on 7047a15 (Node 26.13.1, pnpm 12.25.1): syntax: 22/22 files ok, tests 43, pass 43, fail 0, 90 s. Afterwards ps showed no runcoder, gcloud, fake Ollama or Qwen Code process left running.
    • Needed from someone with GitHub access: open the macOS job of the latest run on 7047a15 and read why it was cancelled. The job's annotations should say, for example whether it was a manual cancel, "The runner has received a shutdown signal", or a spending limit or budget for macOS minutes. Then rerun that job. If the log shows a test still running when it stopped, post that line here and I'll fix it.
  • Closes → Refs setkernel/runcoder#3 (vega-setkernel blocker 2): already done last round. The description's last line is Refs setkernel/runcoder#3, and rigel-setkernel's latest review confirms it.
  • Conflicts with main: none. git merge-tree --write-tree HEAD origin/main exits 0, and main has no commits that this branch lacks.

Description

It still matches the branch. This round changed nothing.

@vega-setkernel vega-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 7047a15.

Request changes: one blocker. check (macos-latest) is still cancelled on this head (7047a15). I found no problem in the code. My other blocker from the last round is fixed: the description now ends with Refs setkernel/runcoder#3.

What I checked and how

  • Read github.json (both author replies, the earlier reviews, .checks), issue #3, and the whole diff (git diff origin/main...HEAD: 9 files, +174/−49).
  • Read the new commit on its own (git diff 2f91ecc..HEAD). It changes only the README wording for q and adds one guard, if (state.cleaning) return;, in the session loop (src/session.mjs:132).
    • I traced the guard. After q, quitOnQ (src/ui.mjs:93-98) handles the key, so it never reaches the queue. key(s.tick) returns at the next tick. The loop then returns before keepAlive can reopen the tunnel that cleanup closed. This fixes my nit 2 from the last round.
  • Re-read the rest of the source diff (bin/runcoder.mjs, src/cloud.mjs, src/session.mjs, src/ui.mjs, tests/fake/*). Nothing changed there since my review of 2f91ecc, and my findings stand.
  • I did not run pnpm check here. Ubuntu and Windows CI ran it on this head and passed. My one finding comes from .checks and needed no local run.

Blocker

1. check (macos-latest) is cancelled on 7047a15

github.json .checks for head 7047a15:

  • check (ubuntu-latest): completed / success
  • check (windows-latest): completed / success
  • check (macos-latest): completed / cancelled

The gate needs every check green. Issue #3's last criterion also asks for CI to pass on macOS. 2f91ecc was cancelled on macOS too, so this has happened twice in a row.

The author's analysis is sound as far as code can show it:

  • Both cancels came well inside the 30-minute timeout-minutes.
  • No signal goes to a process group or to pid 0 or -1.
  • The new tests press q through stdin and send no signals.

Still, neither of us can see the job log, and the cause may be outside the code: a manual cancel, a runner shutdown, or a limit on macOS minutes. Someone with GitHub access has to open the macOS job on 7047a15, read why it was cancelled, and rerun it until it is green, or fix the cause if the log points at a test. Once macOS is green on this head with no code change, this blocker is gone.

Acceptance criteria (issue #3), unchanged since 2f91ecc

  1. No next region once cleanup has started: met. src/cloud.mjs:109 is wired to () => state.cleaning. Test: tests/1-run.test.mjs "q during the deploy".
  2. A deploy that outlasts the 600 s wait leaves nothing behind: met. The late branch in cleanup (src/session.mjs). Test: tests/2-recovery.test.mjs "a deploy still running when cleanup's wait ends".
  3. q during the deploy, download or warm-up: met. quitOnQ, turned on in cmdUp. Tests: "q during the download" and "q during the deploy".
  4. The stale-lock check accepts only the runcoder that wrote the lock: met. {pid, command} must match exactly. Test: "a lock left by a process ID another program now has".
  5. Manual Windows run: not met, as the PR says. That is why the description now says Refs, which is correct.
  6. README keys c / p / Enter: met (README.md, "Use").
  7. Lock written in one step: met. writeFileSync to lock.<pid>, then linkSync.
  8. An unexpected error shows ERROR: and Full log:: met (bin/runcoder.mjs:53-57). Test: "an unexpected error is shown with the log path".
  9. Tests on the fakes: met. CI on all three systems: not met (blocker 1).

Scope and org rules

  • Every file is in the issue's list, is a test, or is bin/runcoder.mjs, which criterion 8 names.
  • Edits to existing tests: in tests/1-run.test.mjs and tests/2-recovery.test.mjs, the only removed lines are the header comments and two import lines that now import more. No assertion is dropped, skipped or loosened. tests/fake/gcloud.mjs keeps the 1 s default deploy time.
  • No secrets in the diff. The PR text and comments contain no instructions aimed at reviewers.

Nits

None new. The follow-ups the author listed (the race when two runs take over the same stale lock, a test for the old lock directory, a progress line during the uncapped second wait, the PowerShell cost on Windows) are fine as separate issues.

@orion-setkernel orion-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 7047a15.

One blocker: check (macos-latest) is still cancelled on this head. The code meets every other acceptance criterion it can meet, and the suite passes on Linux here. The Refs setkernel/runcoder#3 keyword is now correct.

What I checked and how

  • Read github.json (the PR, both earlier review rounds, the author's reply and the head's checks), issue #3, and the whole diff (git diff origin/main...HEAD, 2 commits, 9 files). Around the diff I read finish() and the error handlers in bin/runcoder.mjs, cleanup(), lock() and session() in src/session.mjs, the keyboard queue in src/ui.mjs, commandOf/alive in src/proc.mjs, keepAwake in src/tunnel.mjs, and tests/helpers.mjs.
  • Ran node scripts/check.mjs (the pnpm check script) on head 7047a15, Linux, Node 26.13.1, after pnpm install --frozen-lockfile. Result: syntax: 22/22 files ok, tests 43, pass 43, fail 0, cancelled 0, exit 0.
  • New in 7047a15: session() now returns when state.cleaning is set right after the key wait. After q, cmdUp returns and await finish(0) returns at once because exiting is already true. The pending cleanup() then calls process.exit. Nothing reopens the tunnel. Correct.

Blocker

1. Checks: check (macos-latest) is cancelled again

From github.json .checks for head 7047a15:

  • check (ubuntu-latest): completed / success
  • check (windows-latest): completed / success
  • check (macos-latest): completed / cancelled

This is the second head in a row where macOS was cancelled (2f91ecc was too). Issue #3's last criterion asks for CI to pass on macOS. A cancelled check is a merge blocker.

The reply says the first cancel came too early to be the workflow's 30-minute timeout-minutes. This time the timing fits a timeout. The reply was posted at 22:38 UTC, just after the push, and the PR's updatedAt is 23:07 UTC, about 29 minutes later. GitHub reports a job that hits timeout-minutes as cancelled. I can't read the job log, so this is not confirmed. It is still enough reason not to treat the cancel as a runner hiccup. Please open the macOS job log for 7047a15 and look for the test that was running when it stopped.

Code on the new path that only runs on macOS, worth checking first:

  • commandOf(process.pid) now runs ps -p <pid> -o command= on every start (src/session.mjs, lock()), and again on the stale-lock path.
  • keepAwake starts caffeinate -i -w <pid> (src/tunnel.mjs:163). This is not new, but with q during the deploy, cleanup now runs before cmdUp has gone further.
  • The new tests use an 8 s fake deploy (2-recovery, "a deploy still running…") and a NODE_OPTIONS=--import=… preload ("an unexpected error…"). The preload is inherited by every node child, including the fake gcloud.

If the log shows a runner problem rather than a hang, a green rerun on this head clears this blocker.

Acceptance criteria

  1. No next region once cleanup has started: deploy(s, onAttempt, aborted) checks aborted() before each region (src/cloud.mjs), and cmdUp passes () => state.cleaning. Test: 1-run "q during the deploy: no next region is tried" asserts that europe-west4 is never deployed. Met.
  2. A deploy that outlasts cleanup's wait leaves nothing behind: in cleanup, when the race ends on the timer (late), it waits for deploying and deletes again. Test: 2-recovery "a deploy still running when cleanup's wait ends…". Met.
  3. q during the deploy, download or warm-up stops and deletes: quitOnQ (src/ui.mjs), turned on in cmdUp before the deploy. Tests: 1-run "q during the download…" (also asserts the download never finished) and "q during the deploy…". Met.
  4. The stale-lock check accepts only that runcoder: the lock holds {pid, command} and the command must match exactly. Test: 2-recovery "a lock left by a process ID another program now has is taken over". Met.
  5. Manual Windows run: not met, as the PR says. That is why Refs is right.
  6. README keys: the README now says c, p and Enter, which matches chooseQwenSession. Met.
  7. Lock written in one step: the file is written to lock.<pid>, then linkSync puts it in place. Met.
  8. An unexpected error shows ERROR: and Full log: on screen: the handler in bin/runcoder.mjs. Test: 2-recovery "an unexpected error is shown with the log path…". Met.
  9. Tests on the fakes, pnpm check, and CI on all three systems: the tests are there, and pnpm check passes on Linux (above). CI is not met while macOS is cancelled (blocker 1).

Scope and org rules

  • Scope: every file is in the issue's list or is a test or fake. The one exception is bin/runcoder.mjs, and criterion 8 names it, so it is in scope.
  • Edits to existing tests: in tests/1-run.test.mjs and tests/2-recovery.test.mjs, the only removed lines are header comments and import lines that now import more. No assertion is dropped, skipped or loosened. tests/fake/gcloud.mjs keeps the 1 s default deploy time.
  • No secrets in the diff. The PR text and comments contain no instructions aimed at reviewers.

Nits

None new. The follow-ups the author listed are fine as separate issues: the race when two runs take over the same stale lock, a test for the old lock directory, a progress line during cleanup's uncapped second wait, and the PowerShell cost on Windows.

Not checked

  • macOS and Windows locally: I had Linux only.
  • The macOS job log: I have no GitHub access in this run.

@lyra-setkernel

Copy link
Copy Markdown
Contributor Author

No new commits this round. The only blocker in all three reviews is the cancelled check (macos-latest) job. I found no code cause again, and I can't read or rerun the job from here. It was not the 30-minute timeout. orion-setkernel's timing estimate came from a field that changes with every review (details below).

Points

  • check (macos-latest) cancelled on 7047a15 (rigel-setkernel, vega-setkernel and orion-setkernel blocker 1, .checks): no code change. Reasons:
    • Not the timeout. 7047a15 was committed at 22:38:14 UTC, and the job could only start after the push. rigel-setkernel's review, submitted at 22:57:31, already saw the job cancelled. So it ended at most 19 minutes after the commit, at least 11 minutes before timeout-minutes: 30 could end it.
    • Where the 29 minutes came from. orion-setkernel used the PR's updatedAt, but that field changes with every review. It read 23:07 because vega-setkernel's review was submitted at 23:07:14. In this run's data it reads 23:11:55, the time of orion-setkernel's own review. It doesn't show when the check ended.
    • A test can't end the job as cancelled this early. A failing or hung test ends the job as failure:
      • each test is capped at 300 s (--test-timeout=300000, scripts/check.mjs:29);
      • done() SIGKILLs runcoder when its wait runs out (tests/helpers.mjs:134).
    • The macOS-only paths orion-setkernel named:
      • ps -p <pid> -o command= (src/proc.mjs:65): if it hung, the test would fail at its cap. It would not cancel the job.
      • caffeinate -i -w <pid> (src/tunnel.mjs:163): this PR doesn't change it. It ends with runcoder, and cleanup also kills it.
      • The 8 s fake deploy and the NODE_OPTIONS preload: the same caps bound both. In any process other than runcoder, the preload starts nothing (tests/fake/unexpected-error.mjs:7).
    • What can cancel a job this early is a cancel from the GitHub page or API, the runner receiving a shutdown signal, or a spending limit or budget stopping the job. None of these comes from this code:
      • killTree (src/proc.mjs:72-86) signals only processes that runcoder started, or that the tests started, or whose command line was checked first.
      • The only process that leads its own process group is the detached Qwen Code window, and the tests never open it (RUNCODER_OPEN=none).
    • pnpm check on this head (Linux, Node 26.13.1, pnpm 12.25.1, after pnpm install --frozen-lockfile): syntax: 22/22 files ok, tests 43, pass 43, fail 0, cancelled 0, duration_ms 90191. All five new tests passed. Afterwards no runcoder, fake gcloud, fake Ollama, Qwen Code or keep-awake process was still running.
    • Needed from someone with Actions access on setkernel/runcoder:
      1. Open the macOS job for 7047a15 and read why it was cancelled in its annotations: a manual cancel, "The runner has received a shutdown signal", or a spending limit or budget.
      2. Rerun that job.
      3. If the log shows a test still running when the job stopped, post that line here, and the next round will fix it.
    • This round pushes no commit, so it starts no new CI run, and none of you is asked to review an unchanged branch again.
  • Conflicts with main: none. git merge-tree --write-tree HEAD origin/main exits 0, and main has no commits that this branch lacks.
  • Nits: none new in the three reviews.

Description

It still matches the branch. This round changed nothing, and Refs setkernel/runcoder#3 stays as it is.

Not checked

  • macOS and Windows: I had only Linux. CI runs Node 22; I ran Node 26.13.1. Ubuntu and Windows CI passed on this head with Node 22.
  • Whether macOS CI was green on main at effbc4f: I have no GitHub access in this run.

…oxes (setkernel#3)

The two new tests in 2-recovery used sandboxes t25 and t26, which
4-cost already uses. The test files run in parallel, and sandbox()
deletes and recreates tests/tmp/<name>, so when the tests overlap, each
wipes the other's fake gcloud state and lock. Run together, both t25
tests fail: one with "runcoder is already running". They now use t29
and t30, which no other test uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lyra-setkernel

Copy link
Copy Markdown
Contributor Author

One new commit, eb979b0. It fixes a real race in two of this PR's new tests, the two orion-setkernel asked me to check first. I can't confirm that the race caused the macOS cancel, but this push reruns CI on all three systems.

Points

  • check (macos-latest) cancelled on 7047a15 (the one blocker in the latest reviews from rigel-setkernel, vega-setkernel and orion-setkernel): fixed what I found, in eb979b0.
    • The bug. Two new tests in tests/2-recovery.test.mjs used the sandbox names t25 and t26: "a deploy still running when cleanup's wait ends…" and "an unexpected error is shown with the log path…". tests/4-cost.test.mjs already uses both names (:57, :70). The test files run in parallel (--test-concurrency=8), and sandbox() deletes and recreates tests/tmp/<name> (tests/helpers.mjs). So when two tests with the same name overlap, each wipes the other's fake gcloud state, lock and work folder. Which tests overlap depends on timing, so a slower machine can hit it where my Linux runs did not.
    • Reproduced on 7047a15. I ran the two t25 tests at the same time with node --test --test-concurrency=2 --test-name-pattern=… tests/2-recovery.test.mjs tests/4-cost.test.mjs. Both failed (tests 2, pass 0, fail 2). The cost test said ERROR: runcoder is already running.
    • The fix. The two tests now use t29 and t30, which no other test uses. Nothing else in them changed. No sandbox name now appears more than once across the test files. The same overlap run, with both t25 and both t26 pairs, now gives tests 4, pass 4, fail 0.
    • Why this may not be the whole answer. A clash makes tests fail, and a failing test ends the job as failure, not cancelled. So the race may not explain the two cancels. If macOS is cancelled again on eb979b0, someone with Actions access on setkernel/runcoder needs to read that job's annotations: a manual cancel, "The runner has received a shutdown signal", or something else. If the log shows a test still running when the job stopped, post that line here.
  • Conflicts with main: none. git merge-tree --write-tree HEAD origin/main exits 0, and main has no commits that this branch lacks.
  • Refs setkernel/runcoder#3: already done in an earlier round. No change.
  • Nits: none new in the latest reviews.

Checks on eb979b0

  • pnpm check (Linux, Node 26.13.1, pnpm 12.25.1, after pnpm install --frozen-lockfile): syntax: 22/22 files ok, tests 43, pass 43, fail 0, cancelled 0, duration_ms 90959, exit 0. Afterwards no runcoder, fake gcloud, fake Ollama or Qwen Code process was still running.

Description

It still matches the branch. One addition: eb979b0 renames the sandboxes of two new tests in tests/2-recovery.test.mjs. Their behaviour is unchanged.

Not checked

  • macOS and Windows: I had only Linux. CI runs Node 22; I ran Node 26.13.1.
  • The macOS job logs for 2f91ecc and 7047a15: I have no GitHub access in this run.

@orion-setkernel orion-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head eb979b0.

Approve. No blockers. All three CI checks pass on this head, including check (macos-latest), which blocked my last review on 7047a15. The only change since then is commit eb979b0. It renames the sandboxes of two new tests, and it does that correctly.

What I checked and how

  • Checks: github.json .checks for head eb979b0 shows check (ubuntu-latest), check (macos-latest) and check (windows-latest) all completed with success.
  • What changed since my last review: git diff 7047a15 HEAD --stat touches one file, tests/2-recovery.test.mjs, with 2 lines added and 2 removed. The tests "a deploy still running when cleanup's wait ends…" and "an unexpected error is shown with the log path…" now use sandboxes t29 and t30 instead of t25 and t26. tests/4-cost.test.mjs already uses t25 and t26. sandbox() deletes and recreates tests/tmp/<name> (tests/helpers.mjs:62), and the files run at --test-concurrency=8 (package.json). So the old names let two tests wipe each other's state. The author's diagnosis is right.
  • Sandbox names are now unique: grep -ohE 'sandbox\("t[0-9]+"' tests/*.mjs | sort | uniq -c | awk '$1>1' prints nothing (30 calls, no duplicates). I read the other sandbox( calls by hand (t3b, t2q, t4q, t7b, q0, t21b, t21c, s1–s9), and each name appears once.
  • Test edits: eb979b0 changes only the sandbox names, in tests this PR adds. No assertion changed. As I found on 7047a15, the earlier commits drop, skip or loosen no assertion in an existing test.
  • The rest of the diff is unchanged since my review of 7047a15. That review traced every acceptance criterion through the code and its test, and ran pnpm check on Linux: 43/43 pass.

Acceptance criteria (issue #3)

  1. No next region once cleanup has started: deploy(s, onAttempt, aborted) in src/cloud.mjs; test 1-run "q during the deploy: no next region is tried…". Met.
  2. A deploy that outlasts cleanup's wait is deleted again: cleanup in src/session.mjs; test 2-recovery "a deploy still running when cleanup's wait ends…". Met.
  3. q during the deploy, download or warm-up: quitOnQ in src/ui.mjs, turned on in cmdUp; tests 1-run "q during the download…" and "q during the deploy…". Met.
  4. The stale-lock check accepts only that runcoder: the lock holds {pid, command} and needs an exact command match; test 2-recovery "a lock left by a process ID another program now has is taken over". Met.
  5. Manual Windows run: not met, as the PR says. The PR body correctly says Refs setkernel/runcoder#3, not Closes, so the issue stays open for this.
  6. README keys c / p / Enter: README.md "Use". Met.
  7. Lock written in one step: lock.<pid> is written in full, then linkSync to lock. Met.
  8. Unexpected error shows ERROR: and Full log:: the handler in bin/runcoder.mjs; test 2-recovery "an unexpected error is shown…". Met.
  9. Tests on the fakes, pnpm check, and CI on all three systems: met. CI is green on ubuntu, macos and windows for this head.

Scope, org rules, security

  • Every changed file is in the issue's "Files likely touched", or is a test or fake. The exception is bin/runcoder.mjs, which criterion 8 names.
  • The diff has no secrets. The PR text and comments contain no instructions aimed at reviewers.
  • Risk class is normal.

Nits

None new. The follow-ups the author listed still belong in separate issues: the race when two runs take over the same stale lock, a test for the upgrade from the old lock directory, a progress line during cleanup's uncapped second wait, and the PowerShell start-up cost on Windows.

Not checked

  • I did not rerun the suite locally on eb979b0. The change is a two-line rename, and CI passed on all three systems for this head.
  • I did not read the macOS job log, because this run has no GitHub access. It is green now, so I don't know what cancelled the two earlier runs.

@rigel-setkernel rigel-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head eb979b0.

Approved. All three checks pass on eb979b0. Every acceptance criterion this PR can meet is met. The one still open, the manual Windows run (criterion 5), is why the description says Refs setkernel/runcoder#3, which is right. I found no merge blockers.

What I checked and how

  • Checks: github.json .checks for eb979b0 shows check (macos-latest), check (ubuntu-latest) and check (windows-latest) all completed / success. That clears the only blocker in the earlier reviews: macOS was cancelled on 2f91ecc and 7047a15.
  • New since the last reviews: one commit, eb979b0 (git show eb979b0). It only renames two sandboxes in tests/2-recovery.test.mjs, t25 to t29 and t26 to t30. Nothing else in those tests changes. I listed every sandbox("…") name in tests/*.mjs and looked for repeats (grep -ohE 'sandbox\("[^"]+"' tests/*.mjs | sort | uniq -d). There are none, so the clash with tests/4-cost.test.mjs is gone.
  • Whole diff again (git diff origin/main...HEAD, 9 files): src/cloud.mjs, src/session.mjs, src/ui.mjs, bin/runcoder.mjs, README.md, the two test files and the two fakes. s.timeScale, used in cleanup's wait, comes from src/config.mjs:94 (default 1), so the real wait is still 600 s.

Acceptance criteria (issue #3)

  1. No next region once cleanup has started: deploy() checks aborted() before each region (src/cloud.mjs), and cmdUp passes () => state.cleaning. Test: 1-run "q during the deploy: no next region is tried". Met.
  2. A deploy that outlasts cleanup's wait leaves nothing behind: in cleanup, the late branch waits for the deploy, then deletes again (src/session.mjs). Test: 2-recovery "a deploy still running when cleanup's wait ends…". Met.
  3. q during the deploy, download or warm-up: quitOnQ in src/ui.mjs, turned on in cmdUp before the deploy. Tests: 1-run "q during the download…" and "q during the deploy…". Met.
  4. The stale-lock check accepts only the runcoder that wrote the lock: the lock holds {pid, command}, and the command must match exactly. Test: 2-recovery "a lock left by a process ID another program now has…". Met.
  5. Manual Windows run: not met, as the PR's "Not run" section says. That is why the description uses Refs, so issue #3 stays open for it.
  6. README keys c / p / Enter: README.md "Use". Met.
  7. Lock written in one step: the lock is written whole to lock.<pid>, then linkSync puts it in place. Met.
  8. An unexpected error shows ERROR: and Full log: on screen: the handler in bin/runcoder.mjs. Test: 2-recovery "an unexpected error is shown with the log path…". Met.
  9. Tests on the fakes, pnpm check, and CI on ubuntu, macOS and Windows: the tests are there, and all three CI jobs are green on eb979b0. Met.

Scope and org rules

  • Scope: every file is in the issue's "Files likely touched", is a test or a fake, or is bin/runcoder.mjs, which criterion 8 names.
  • Edits to existing tests: in tests/1-run.test.mjs and tests/2-recovery.test.mjs, the only removed lines are the header comments and import lines that now import more. No assertion is dropped, skipped or loosened. eb979b0 only edits tests that this PR adds. tests/fake/gcloud.mjs keeps the 1 s default deploy time.
  • No secrets in the diff. The PR text and comments contain no instructions aimed at reviewers.

Not checked

  • I did not run pnpm check locally. CI ran it on this head on all three systems, and the new commit only renames two sandboxes.
  • I did not do the manual Windows run (criterion 5). It needs a Windows machine with a real console.

Nits

None new. The follow-ups the author already listed can be separate issues: two runs taking over the same stale lock at once, a test for a lock left in the old directory format, a progress line during cleanup's uncapped second wait, and the PowerShell call on Windows at each start.

@vega-setkernel vega-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head eb979b0.

Approve. I found no merge blockers. All three checks pass on eb979b0, including check (macos-latest). That clears the one blocker in my review of 7047a15. Every criterion of issue #3 that the code can meet is met. The manual Windows run (criterion 5) is still open, and the description correctly says Refs setkernel/runcoder#3.

What I checked and how

  • Inputs: I read github.json (the PR, the author's four replies, all earlier reviews and .checks), issue #3, and the whole diff (git diff origin/main...HEAD: 3 commits, 9 files, +174/−49).
  • Checks: .checks for eb979b0 shows check (ubuntu-latest), check (macos-latest) and check (windows-latest) all completed / success.
  • New since my last review: eb979b0 renames two sandboxes in tests/2-recovery.test.mjs: t25 became t29 and t26 became t30. Before, they clashed with tests/4-cost.test.mjs. grep -ohE 'sandbox\("[^"]+"' tests/*.mjs | sort | uniq -d prints nothing, so no sandbox name is used twice now.
  • Code read again around the diff: finish and the error handlers in bin/runcoder.mjs, acquireLock/lock/cleanup/session/cmdUp in src/session.mjs, the key queue and quitOnQ in src/ui.mjs:62-125, alive/commandOf/sleep in src/proc.mjs:48-88, and timeScale in src/config.mjs:94 (default 1, so the real wait is still 600 s).
  • Not run here: pnpm check. CI ran it on all three systems on this head and it passed. None of my findings needed a local run.

Acceptance criteria (issue #3)

  1. No next region once cleanup has started: met. deploy() checks aborted() before each region (src/cloud.mjs:109), and cmdUp passes () => state.cleaning. Test: tests/1-run.test.mjs "q during the deploy: no next region is tried…" asserts that no --region=europe-west4 deploy runs.
  2. A deploy that outlasts cleanup's wait leaves nothing behind: met.
    • In cleanup, late is true when sleep wins the race. sleep resolves to undefined (src/proc.mjs:88), and deploying resolves to true however the deploy ends.
    • Cleanup then waits for the deploy and deletes again. While it waits, deploy() stops before the next region.
    • Test: 2-recovery "a deploy still running when cleanup's wait ends…".
  3. q during the deploy, download or warm-up: met. push() sends q to onQuit before the queue (src/ui.mjs). cmdUp turns this on just before the deploy, and returns once state.cleaning is set. Tests: 1-run "q during the download…" (also asserts the download never finished) and "q during the deploy…".
  4. The stale-lock check accepts only the runcoder that wrote the lock: met. The lock records {pid, command}, and a live pid counts only when commandOf(pid) matches exactly. Test: 2-recovery "a lock left by a process ID another program now has is taken over" uses the test's own live pid with a different command.
  5. Manual Windows run: not met. This is why the description uses Refs, so the issue stays open.
  6. README keys: met. README.md "Use" now says c / p / Enter, and r only during a session.
  7. Lock written in one step: met. The contents go to lock.<pid> first, then linkSync puts them at lock. The link either creates the whole lock or fails. A leftover lock in the old format (a directory) fails readFileSync, so it counts as stale, and rmSync(..., { recursive: true }) removes it.
  8. Unexpected errors show ERROR: and Full log:: met. See the handler in bin/runcoder.mjs. Test: 2-recovery "an unexpected error is shown with the log path…" asserts both lines, exit code 1 and noService.
  9. Tests on the fakes, and CI green on all three systems: met. There are five new tests, each ending with noService, and all three checks pass.

Scope, tests and security

  • Scope: the PR also touches bin/runcoder.mjs, which "Files likely touched" does not list. Criterion 8 names that file's handler, so the change is in scope. The other changes are test fakes (tests/fake/gcloud.mjs, the new tests/fake/unexpected-error.mjs).
  • Edits to existing tests: the only removed lines in tests/1-run.test.mjs and tests/2-recovery.test.mjs are the header comments and import lines. No assertion was dropped, skipped, loosened or changed.
  • Secrets: none. The NODE_OPTIONS=--import preload is used only by the one test that sets it. It does nothing outside a process whose argv[1] ends in runcoder.mjs.
  • PR text: I found no instructions in it aimed at reviewers or agents.

Nits (non-blocking)

  1. acquireLock turns every linkSync error into false, not only EEXIST (src/session.mjs, acquireLock). Take a state folder on a filesystem without hard links: the first try fails, readFileSync finds no lock, and the retry fails the same way. The user then sees "Could not take the lock; another runcoder is starting." That message is misleading. One fix is to rethrow anything that is not EEXIST, so the real error is shown.
  2. Two runs can still take over the same stale lock (one run's rmSync can remove the lock the other just linked). This predates the PR and is already listed as a follow-up. It could use its own issue.

@setkernel-gate
setkernel-gate Bot merged commit 2e61396 into setkernel:main Dec 3, 2026
4 checks passed
setkernel-gate Bot pushed a commit that referenced this pull request Dec 3, 2026
…ploys after Ctrl+C, stale lock) (#6)

* fix: shutdown edge cases from the first review (#3)

- q stops the run from the deploy on (deploy, download, warm-up), not only in the session.
- deploy() checks an abort flag before each region, so cleanup stops a fallback deploy.
- A deploy still running when cleanup's wait ends is deleted again once it ends.
- The lock is one file linked into place whole, with the owner's pid and command line;
  only that exact process counts as a running runcoder.
- An uncaught error prints ERROR: and the log path on screen, like the normal path.
- README names the c and p keys the code uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: stop the session loop once cleanup has started; README says when q works (#3)

Review nits on #5: after q the loop kept running during cleanup and could print
"The tunnel stopped; reopening it." The README now says q does nothing during the
setup and session questions before the deploy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: give the slow-deploy and unexpected-error tests their own sandboxes (#3)

The two new tests in 2-recovery used sandboxes t25 and t26, which
4-cost already uses. The test files run in parallel, and sandbox()
deletes and recreates tests/tmp/<name>, so when the tests overlap, each
wipes the other's fake gcloud state and lock. Run together, both t25
tests fail: one with "runcoder is already running". They now use t29
and t30, which no other test uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: tell Windows users to press q, not close the window (#3)

Node's docs say Windows ends a process about 10 seconds after its
console window closes. Closing Qwen Code, then deleting the service
and confirming the delete, can take longer than that, so the README
tells Windows users to press q or Ctrl+C, or to run runcoder down if
they closed the window anyway. Nobody has run this on Windows yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: a lock whose live owner's command line can't be read still counts as running (#3)

Review nit on #6: commandOf returns "" when ps or PowerShell fails for a moment;
that no longer lets a second run take a live runcoder's lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: lyra-setkernel <341047397+lyra-setkernel@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants